package com.example.hello.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import jakarta.servlet.http.HttpServletRequest;

public class SecurityUtil {
    
    public static String getCurrentUsername() {
        return (String) getRequest().getAttribute("username");
    }
    
    public static Integer getCurrentEmployeeId() {
        return (Integer) getRequest().getAttribute("employeeId");
    }
    
    private static HttpServletRequest getRequest() {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (attributes == null) {
            throw new IllegalStateException("当前不在Web上下文中");
        }
        return attributes.getRequest();
    }
} 